package com.javaclimb.houserent.common.dto;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 用于前后端传输的JSON的数据格式  大对象
 */

@Data
@Accessors(chain = true)
public class JsonResult {
    //返回的状态码 0失败  1 成功
    private Integer code;

    //返回的信息
    private String msg;

    //返回的数据
    private Object result;

    public JsonResult(Integer code, String msg, Object result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public JsonResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;

    }

    public JsonResult(Integer code, Object result) {
        this.code = code;
        this.result = result;
    }

    //成功的返回
    public static JsonResult success() {
        return new JsonResult(1, "操作成功");
    }

    //成功的返回
    public static JsonResult success(String msg) {
        return new JsonResult(1, msg);
    }

    //成功的返回
    public static JsonResult success(String msg, Object result) {
        return new JsonResult(1, msg, result);
    }

    //失败的返回
    public static JsonResult error(String msg) {
        return new JsonResult(0, msg);
    }

    //失败的返回
    public static JsonResult error(String msg, Object result) {
        return new JsonResult(0, msg, result);
    }
}
